<?php

use yii\helpers\Html;
use app\core\lib\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\FormInput */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="box-body">
    <?php $form = ActiveForm::begin([
        'options' => ['class' => 'form-horizontal'],
        'fieldConfig' => [
            'template' => "{label}\n<div class=\"col-lg-8\">{input}</div>\n<div class=\"col-lg-2\">{error}</div>",
            'labelOptions' => ['class' => 'col-lg-1 control-label'],
        ],
    ]); ?>

    <?= $form->field($model, 'form_id')->textInput(['disabled' => true]) ?>

    <?= $form->field($model, 'label')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'type')->dropDownList(\app\models\FormInputAttr::inputType(), ['prompt' => '请选择输入框类型']) ?>

    <?= $form->field($model, 'ismust')->dropDownList(\app\models\FormInputAttr::is_must(), ['prompt' => '是否必填']) ?>

    <?= $form->field($model, 'options')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'default_value')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'sort')->textInput() ?>

    <?= Html::submitButton(Html::tag('span', '', ['class' => 'glyphicon glyphicon-floppy-disk']) . ' ' .
        ($model->isNewRecord ? 'Create' : 'Save'),
        ['class' => $model->isNewRecord ? 'btn btn-success pull-right' : 'btn btn-primary pull-right']) ?>
    <?php ActiveForm::end(); ?>
</div>
<?php $this->render('@app/modules/admin//views/layouts/modal-form', ['form' => $form]) ?>
<?php
$jsStr = <<<EOF
    var options = $('.field-forminput-options');
    var defaultVal = $('.field-forminput-default_value');
    options.hide();
    defaultVal.hide();

    $('#forminput-type').on('change', function(){
        var value = $(this).val();
        if (value == 'checkbox' || value == 'radio') {
            options.show('slow');
            defaultVal.show('slow');
        } else { 
            options.hide('slow');
            defaultVal.hide('slow');
        }
    })
EOF;
$this->registerJs($jsStr);

